import { NextResponse } from 'next/server'; import { loadSession } from '@/lib/ai/research'; import { currentUserId, getAnonId } from '@/lib/ai/request'; export const runtime = 'nodejs'; export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) { const { id } = await ctx.params; const [userId, anonId] = await Promise.all([currentUserId(), getAnonId(false)]); const loaded = await loadSession(id, { anonId, userId }); if (!loaded) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ session: { id: loaded.session.id, title: loaded.session.title, usdEst: loaded.session.usdEst, model: loaded.session.model }, messages: loaded.messages.map((m) => ({ id: m.id, role: m.role, content: m.content, toolCalls: m.toolCalls, createdAt: m.createdAt })), }); }